package 语雀题目21至55.a31至40;

/**
 * ClassName: 求1至100的和
 * Package: 语雀题目21至40.a31至40
 * Description:
 *
 * @Author fjorid
 * @Create 2025/1/7 19:40
 * @Version 1.0
 */
public class 求1至100的和39 {
    public static void main(String[] args) {
        int sum = 0;
        /*for (int i = 1; i <= 100; i++) {
            sum += i;
        }
        System.out.println(sum);
        使用for循环遍历*/
        int first = 1, last = 100;//使用等差数列求和公式
        int d = 1;
        //int terms = (last-first)/d+1;
        //sum = (first+last)*terms/2;
        sum = (first + last) * ((last - first) / d + 1) / 2;
        System.out.println(sum);
    }
}
